home *** CD-ROM | disk | FTP | other *** search
/ Amiga Magazin: Amiga-CD 1996 March / Amiga-CD 1996 #3.iso / pd-software / mui_3.1 / developer / c / examples / virtual.c < prev    next >
C/C++ Source or Header  |  1996-01-19  |  13KB  |  417 lines

  1. #include "demo.h"
  2.  
  3.  
  4. static const char *Pages[] =
  5. {
  6.     "Big Text Field",
  7.     "Different Objects",
  8.     "Input Accepting Objects",
  9.     "Completly Crazy",
  10.     NULL,
  11. };
  12.  
  13.  
  14. static const char text1[] = "\
  15. \33iHello User !\33n\n\
  16. \n\
  17. This could be a very long text and you are looking\n\
  18. at it through a \33uvirtual group\33n. Please use the\n\
  19. scrollbars at the right and bottom of the group to\n\
  20. move the visible area either vertically or\n\
  21. horizontally. While holding down the small arrow\n\
  22. button between both scrollbars, the display will\n\
  23. follow your mouse moves.\n\
  24. \n\
  25. If you click somewhere into a \33uvirtual group\33n and\n\
  26. move the mouse across one of its borders, the group will\n\
  27. start scrolling. If you are lucky and own a middle mouse\n\
  28. button, you may also want to press it and try moving.\n\
  29. \n\
  30. When the surrounding window is big enough for the\n\
  31. complete virtual group to fit, the scrollers and\n\
  32. the move button get disabled.\n\
  33. \n\
  34. Since this \33uvirtual group\33n does only contain a\n\
  35. single text object, it's a rather simple example.\n\
  36. In fact, virtual groups are a lot more powerful,\n\
  37. they can contain any objects you like.\n\
  38. \n\
  39. Note to 7MHz/68000 users: Sorry if you find this\n\
  40. thingy a bit slow. Clipping in virtual groups can\n\
  41. get quite complicated. Please don't blame me,\n\
  42. blame your 'out of date' machine! :-)\n\
  43. \n\
  44. \33i\33cHave fun, Stefan.\33n\
  45. ";
  46.  
  47.  
  48. APTR MakePage1(VOID)
  49. {
  50.     return
  51.     (
  52.     ScrollgroupObject,
  53.         MUIA_Scrollgroup_Contents, VirtgroupObject,
  54.             VirtualFrame,
  55.             Child, TextObject,
  56.                 MUIA_Background, MUII_TextBack,
  57.                 MUIA_Text_Contents, text1,
  58.                 End,
  59.             End,
  60.         End
  61.     );
  62. }
  63.  
  64.  
  65. static const char text2[] = "\33c\
  66. As you can see, this virtual group contains a\n\
  67. lot of different objects. The (virtual) width\n\
  68. and height of the virtual group are automatically\n\
  69. calculated from the default width and height of\n\
  70. the virtual groups contents.\
  71. ";
  72.  
  73.  
  74. APTR MakePage2(VOID)
  75. {
  76.     #define img(nr)  ImageObject, MUIA_Image_Spec, nr, End
  77.  
  78.     APTR obj = ScrollgroupObject,
  79.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame,
  80.             Child, TextObject,
  81.                 TextFrame,
  82.                 MUIA_Background, MUII_TextBack,
  83.                 MUIA_Text_Contents, text2,
  84.                 End,
  85.             Child, HGroup,
  86.                 Child, ColGroup(2), GroupFrameT("Standard Images"),
  87.                     Child, Label("ArrowUp:"    ), Child, img(MUII_ArrowUp    ),
  88.                     Child, Label("ArrowDown:"  ), Child, img(MUII_ArrowDown  ),
  89.                     Child, Label("ArrowLeft:"  ), Child, img(MUII_ArrowLeft  ),
  90.                     Child, Label("ArrowRight:" ), Child, img(MUII_ArrowRight ),
  91.                     Child, Label("RadioButton:"), Child, img(MUII_RadioButton),
  92.                     Child, Label("File:"       ), Child, img(MUII_PopFile    ),
  93.                     Child, Label("HardDisk:"   ), Child, img(MUII_HardDisk   ),
  94.                     Child, Label("Disk:"       ), Child, img(MUII_Disk       ),
  95.                     Child, Label("Chip:"       ), Child, img(MUII_Chip       ),
  96.                     Child, Label("Drawer:"     ), Child, img(MUII_Drawer     ),
  97.                     End,
  98.                 Child, VGroup, GroupFrameT("Some Backgrounds"),
  99.                     Child, HGroup,
  100.                         Child, RectangleObject, TextFrame, MUIA_Background, MUII_BACKGROUND , MUIA_FixWidth, 30, End,
  101.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILL       , MUIA_FixWidth, 30, End,
  102.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOW     , MUIA_FixWidth, 30, End,
  103.                         End,
  104.                     Child, HGroup,
  105.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWBACK , MUIA_FixWidth, 30, End,
  106.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWFILL , MUIA_FixWidth, 30, End,
  107.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHADOWSHINE, MUIA_FixWidth, 30, End,
  108.                         End,
  109.                     Child, HGroup,
  110.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLBACK   , MUIA_FixWidth, 30, End,
  111.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_SHINEBACK  , MUIA_FixWidth, 30, End,
  112.                      Child, RectangleObject, TextFrame, MUIA_Background, MUII_FILLSHINE  , MUIA_FixWidth, 30, End,
  113.                         End,
  114.                     End,
  115.                 End,
  116.             Child, ColGroup(2), GroupFrame,
  117.                 Child, Label1("Gauge:"), Child, GaugeObject, GaugeFrame, MUIA_Gauge_Current, 66, MUIA_Gauge_Horiz, TRUE, End,
  118.                 Child, VSpace(0)       , Child, ScaleObject, End,
  119.                 End,
  120.             End,
  121.         End;
  122.  
  123.     return(obj);
  124. }
  125.  
  126.  
  127. static const char text3[] = "\
  128. \33cThe above pages only showed 'read only' groups,\n\
  129. no user actions within them were possible. Of course,\n\
  130. handling user actions in a virtual group is not a\n\
  131. problem for MUI. As I promised on the first page,\n\
  132. you can use virtual groups with whatever objects\n\
  133. you want. Here's a small example...\n\
  134. \n\
  135. Note: Due to some limitations of the operating system,\n\
  136. it is not possible to clip gadgets depending on\n\
  137. intuition.library correctly. This affects the appearence\n\
  138. of string and proportional objects in virtual groups.\n\
  139. You will only be able to use these gadgets when they\n\
  140. are completely visible.\n\
  141. \n\
  142. PS: Also try TAB cycling here!\
  143. ";
  144.  
  145. static const char *CYA_Computer[] = { "Amiga 500","Amiga 600","Amiga 1000 :)","Amiga 1200","Amiga 2000","Amiga 3000","Amiga 4000", "Amiga 4000T", "Atari ST :(", NULL };
  146. static const char *CYA_Printer[]  = { "HP Deskjet","NEC P6","Okimate 20",NULL };
  147. static const char *CYA_Display[]  = { "A1081","NEC 3D","A2024","Eizo T660i",NULL };
  148.  
  149. static APTR CY_Computer,CY_Printer,CY_Display;
  150. static APTR MT_Computer,MT_Printer,MT_Display;
  151. static APTR LV_Computer;
  152. static APTR BT_Button[12];
  153.  
  154. APTR MakePage3(VOID)
  155. {
  156.     APTR obj;
  157.  
  158.     obj = ScrollgroupObject,
  159.         MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, 
  160.             Child, TextObject,
  161.                 TextFrame,
  162.                 MUIA_Background, MUII_TextBack,
  163.                 MUIA_Text_Contents, text3,
  164.                 End,
  165.             Child, VGroup,
  166.                 Child, HGroup,
  167.                     Child, MT_Computer = Radio("Computer:",CYA_Computer),
  168.                     Child, VGroup,
  169.                         Child, MT_Printer = Radio("Printer:",CYA_Printer),
  170.                         Child, VSpace(0),
  171.                         Child, MT_Display = Radio("Display:",CYA_Display),
  172.                         End,
  173.                     Child, VGroup,
  174.                         Child, ColGroup(2), GroupFrameT("Cycle Gadgets"),
  175.                             Child, KeyLabel1("Computer:",'c'), Child, CY_Computer = KeyCycle(CYA_Computer,'c'),
  176.                             Child, KeyLabel1("Printer:" ,'p'), Child, CY_Printer  = KeyCycle(CYA_Printer ,'p'),
  177.                             Child, KeyLabel1("Display:" ,'d'), Child, CY_Display  = KeyCycle(CYA_Display ,'d'),
  178.                             End,
  179.                         Child, LV_Computer =    ListviewObject,
  180.                             MUIA_Listview_Input, TRUE,
  181.                             MUIA_Listview_List, ListObject, InputListFrame, End,
  182.                             End,
  183.                         End,
  184.                     End,
  185.                 Child, ColGroup(4), GroupFrameT("Button Field"),
  186.                     Child, BT_Button[ 0] = SimpleButton("Button"),
  187.                     Child, BT_Button[ 1] = SimpleButton("Button"),
  188.                     Child, BT_Button[ 2] = SimpleButton("Button"),
  189.                     Child, BT_Button[ 3] = SimpleButton("Button"),
  190.                     Child, BT_Button[ 4] = SimpleButton("Button"),
  191.                     Child, BT_Button[ 5] = SimpleButton("Button"),
  192.                     Child, BT_Button[ 6] = SimpleButton("Button"),
  193.                     Child, BT_Button[ 7] = SimpleButton("Button"),
  194.                     Child, BT_Button[ 8] = SimpleButton("Button"),
  195.                     Child, BT_Button[ 9] = SimpleButton("Button"),
  196.                     Child, BT_Button[10] = SimpleButton("Button"),
  197.                     Child, BT_Button[11] = SimpleButton("Button"),
  198.                     End,
  199.                 End,
  200.             End,
  201.         End;
  202.  
  203.     if (LV_Computer)
  204.         DoMethod(LV_Computer,MUIM_List_Insert,CYA_Computer,-1,MUIV_List_Insert_Bottom);
  205.  
  206.     return(obj);
  207. }
  208.  
  209.  
  210. #define mytxt(txt)\
  211.     TextObject,\
  212.         MUIA_Text_Contents, "\33c"txt,\
  213.         MUIA_Text_SetMax, TRUE,\
  214.         End
  215.  
  216. #define ibt(i)\
  217.     ImageObject,\
  218.         ImageButtonFrame,\
  219.         MUIA_Background, MUII_ButtonBack,\
  220.         MUIA_InputMode , MUIV_InputMode_RelVerify,\
  221.         MUIA_Image_Spec, i,\
  222.         End
  223.  
  224. static char *x4Sex[]     = { "male","female",NULL };
  225. static char *x4Pages[]   = { "Race","Class","Armors","Weapons","Levels",NULL };
  226. static char *x4Races[]   = { "Human","Elf","Dwarf","Hobbit","Gnome",NULL };
  227. static char *x4Classes[] = { "Warrior","Rogue","Bard","Monk","Magician","Archmage",NULL };
  228. static char *x4Weapons[] = { "Staff","Dagger","Sword","Axe","Grenade",NULL };
  229.  
  230. APTR MakePage4(VOID)
  231. {
  232.     APTR bt1,bt2,bt3,bt4,gr,obj,pcy,pgr;
  233.  
  234.     obj = ScrollgroupObject,
  235.         MUIA_Scrollgroup_Contents, ColGroupV(3), VirtualFrame, 
  236.             MUIA_Group_Spacing, 10,
  237.             Child, VGroup, GroupFrame,
  238.                 Child, HGroup,
  239.                     Child, HSpace(0),
  240.                     Child, bt1 = ibt(MUII_ArrowUp),
  241.                     Child, HSpace(0),
  242.                     End,
  243.                 Child, HGroup,
  244.                     Child, bt2 = ibt(MUII_ArrowLeft),
  245.                     Child, bt3 = ibt(MUII_ArrowRight),
  246.                     End,
  247.                 Child, HGroup,
  248.                     Child, HSpace(0),
  249.                     Child, bt4 = ibt(MUII_ArrowDown),
  250.                     Child, HSpace(0),
  251.                     End,
  252.                 End,
  253.             Child, mytxt("Ever wanted to see\na virtual group in\na virtual group?"),
  254.             Child, HVSpace,
  255.             Child, mytxt("Here it is!"),
  256.  
  257.             Child, ScrollgroupObject,
  258.                 MUIA_Scrollgroup_Contents, gr = VGroupV, VirtualFrame,
  259.                     Child, ColGroup(6), MUIA_Group_SameSize, TRUE,
  260.                         Child, SimpleButton("One"),
  261.                         Child, SimpleButton("Two"),
  262.                         Child, SimpleButton("Three"),
  263.                         Child, SimpleButton("Four"),
  264.                         Child, SimpleButton("Five"),
  265.                         Child, SimpleButton("Six"),
  266.                         Child, SimpleButton("Eighteen"),
  267.                         Child, mytxt("The"),
  268.                         Child, mytxt("red"),
  269.                         Child, mytxt("brown"),
  270.                         Child, mytxt("fox"),
  271.                         Child, SimpleButton("Seven"),
  272.                         Child, SimpleButton("Seventeen"),
  273.                         Child, mytxt("dog."),
  274.                         Child, SimpleButton("Nineteen"),
  275.                         Child, SimpleButton("Twenty"),
  276.                         Child, mytxt("jumps"),
  277.                         Child, SimpleButton("Eight"),
  278.                         Child, SimpleButton("Sixteen"),
  279.                         Child, mytxt("lazy"),
  280.                         Child, mytxt("the"),
  281.                         Child, mytxt("over"),
  282.                         Child, mytxt("quickly"),
  283.                         Child, SimpleButton("Nine"),
  284.                         Child, SimpleButton("Fifteen"),
  285.                         Child, SimpleButton("Fourteen"),
  286.                         Child, SimpleButton("Thirteen"),
  287.                         Child, SimpleButton("Twelve"),
  288.                         Child, SimpleButton("Eleven"),
  289.                         Child, SimpleButton("Ten"),
  290.                         End,
  291.                     End,
  292.                 End,
  293.  
  294.             Child, mytxt("Do you like it? I hope..."),
  295.             Child, HVSpace,
  296.             Child, mytxt("I admit, it's a\n bit crazy... :-)\nBut it demonstrates\nthe power of\n\33bobject oriented\33n\nGUI design."),
  297.  
  298.             Child, ScrollgroupObject,
  299.                 MUIA_Scrollgroup_Contents, VGroupV, VirtualFrame, InnerSpacing(4,4), 
  300.                     Child, VGroup,
  301.                         Child, pcy = Cycle(x4Pages),
  302.                         Child, pgr = PageGroup,
  303.                             Child, HCenter(Radio(NULL,x4Races)),
  304.                             Child, HCenter(Radio(NULL,x4Classes)),
  305.                             Child, HGroup,
  306.                                 Child, HSpace(0),
  307.                                 Child, ColGroup(2),
  308.                                     Child, Label1("Cloak:" ), Child, CheckMark(TRUE),
  309.                                     Child, Label1("Shield:"), Child, CheckMark(TRUE),
  310.                                     Child, Label1("Gloves:"), Child, CheckMark(TRUE),
  311.                                     Child, Label1("Helm:"  ), Child, CheckMark(TRUE),
  312.                                     End,
  313.                                 Child, HSpace(0),
  314.                                 End,
  315.                             Child, HCenter(Radio(NULL,x4Weapons)),
  316.                             Child, ColGroup(2),
  317.                                 Child, Label("Experience:"  ), Child, Slider(0,100, 3),
  318.                                 Child, Label("Strength:"    ), Child, Slider(0,100,42),
  319.                                 Child, Label("Dexterity:"   ), Child, Slider(0,100,24),
  320.                                 Child, Label("Condition:"   ), Child, Slider(0,100,39),
  321.                                 Child, Label("Intelligence:"), Child, Slider(0,100,74),
  322.                                 End,
  323.                             End,
  324.                         End,
  325.                     End,
  326.                 End,
  327.  
  328.  
  329.             End,
  330.         End;
  331.  
  332.     if (obj)
  333.     {
  334.         DoMethod(bt1,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,0);
  335.         DoMethod(bt2,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,0);
  336.         DoMethod(bt3,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Left,9999);
  337.         DoMethod(bt4,MUIM_Notify,MUIA_Pressed,FALSE,gr,3,MUIM_Set,MUIA_Virtgroup_Top ,9999);
  338.  
  339.         DoMethod(pcy,MUIM_Notify,MUIA_Cycle_Active,MUIV_EveryTime,
  340.             pgr,3,MUIM_Set,MUIA_Group_ActivePage,MUIV_TriggerValue);
  341.     }
  342.  
  343.     return(obj);
  344. }
  345.  
  346.  
  347. int main(int argc,char *argv[])
  348. {
  349.     static APTR app,window;
  350.  
  351.     init();
  352.  
  353.     app = ApplicationObject,
  354.         MUIA_Application_Title      , "VirtualDemo",
  355.         MUIA_Application_Version    , "$VER: VirtualDemo 12.9 (21.11.95)",
  356.         MUIA_Application_Copyright  , "©1993, Stefan Stuntz",
  357.         MUIA_Application_Author     , "Stefan Stuntz",
  358.         MUIA_Application_Description, "Show virtual groups.",
  359.         MUIA_Application_Base       , "VIRTUALDEMO",
  360.  
  361.         SubWindow, window = WindowObject,
  362.             MUIA_Window_Title, "Virtual Groups",
  363.             MUIA_Window_ID   , MAKE_ID('V','I','R','T'),
  364.             WindowContents, ColGroup(2), GroupSpacing(8),
  365.                 Child, MakePage1(),
  366.                 Child, MakePage2(),
  367.                 Child, MakePage3(),
  368.                 Child, MakePage4(),
  369.                 End,
  370.             End,
  371.         End;
  372.  
  373.  
  374.     if (!app)
  375.         fail(app,"Failed to create Application.");
  376.  
  377.  
  378.     DoMethod(window,MUIM_Notify,MUIA_Window_CloseRequest,TRUE,
  379.         app,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  380.  
  381.     DoMethod(window,MUIM_Window_SetCycleChain,
  382.         MT_Computer,MT_Printer,MT_Display,
  383.         CY_Computer,CY_Printer,CY_Display,
  384.         LV_Computer,
  385.         BT_Button[ 0],BT_Button[ 1],BT_Button[ 2],BT_Button[ 3],
  386.         BT_Button[ 4],BT_Button[ 5],BT_Button[ 6],BT_Button[ 7],
  387.         BT_Button[ 8],BT_Button[ 9],BT_Button[10],BT_Button[11],
  388.         NULL);
  389.  
  390. /*
  391. ** This is the ideal input loop for an object oriented MUI application.
  392. ** Everything is encapsulated in classes, no return ids need to be used,
  393. ** we just check if the program shall terminate.
  394. ** Note that MUIM_Application_NewInput expects sigs to contain the result
  395. ** from Wait() (or 0). This makes the input loop significantly faster.
  396. */
  397.  
  398.     set(window,MUIA_Window_Open,TRUE);
  399.  
  400.     {
  401.         ULONG sigs = 0;
  402.  
  403.         while (DoMethod(app,MUIM_Application_NewInput,&sigs) != MUIV_Application_ReturnID_Quit)
  404.         {
  405.             if (sigs)
  406.             {
  407.                 sigs = Wait(sigs | SIGBREAKF_CTRL_C);
  408.                 if (sigs & SIGBREAKF_CTRL_C) break;
  409.             }
  410.         }
  411.     }
  412.  
  413.     set(window,MUIA_Window_Open,FALSE);
  414.  
  415.     fail(app,NULL);
  416. }
  417.